#ifndef __SERVER_SESSION_MANAGER_H__
#define __SERVER_SESSION_MANAGER_H__


#pragma once

#include <SolarHashTable.h>
#include <Singleton.h>
using namespace util;

class ServerSession;
class ServerSessionFactory;

class ServerSessionManager : public Singleton<ServerSessionManager>
{
public:
	ServerSessionManager();
	~ServerSessionManager();


	VOID								Init();
	VOID								Release( ServerSessionFactory * pPoolFactory );
	VOID								AddServer( ServerSession * pServer );
	VOID								RemoveServer( DWORD dwSessionIndex );
	ServerSession *						FindServer( DWORD dwSessionIndex );

	VOID								Process();

	template <class ObjectOperator>
	VOID								Foreach( ObjectOperator  & op )
	{
		ServerSession * pSession = NULL;
		m_pSessionHashTable->SetFirst();
		while( ( pSession = m_pSessionHashTable->GetNext() ) != NULL )
		{
			op( pSession );
		}
	}
private:
	enum { _MAX_SESSION_BUCKET_SIZE = 10 };
	SolarHashTable<ServerSession *> *		m_pSessionHashTable;
};

#endif // __SERVER_SESSION_MANAGER_H__